HAL FLASH ITF function migration ¶
This section provides information about the HAL FLASH ITF function migration.
Note
In HAL1, the FLASH driver manages Flash memory operations.
In HAL2, depending on the device family, memory operations are managed either by the FLASH driver or by the NVM driver.
In this migration guide, when an equivalent HAL2 function exists for both FLASH and NVM, the migration is illustrated using the HAL2 FLASH function. The same rule applies to the HAL2 NVM function.
Example: in HAL1,
HAL_FLASHEx_ConfigPrivMode()function becomes:HAL_FLASH_ITF_SetPrivAttr()in HAL2 FLASH driver.HAL_NVM_ITF_SetPrivAttr()in HAL2 NVM driver.
For NVM-based families, the NVM driver provides services similar to those of FLASH with minor differences:
There is no erase step for NVM memories.
Erase-by-address, page erase, bank erase, and FLASH mass erase remain FLASH-specific services.
For NVM-based families, the only erase service that may be exposed is OBK erase, when that feature exists.
Retrieves advanced option byte configuration. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit);
|
HAL_FLASH_ITF_OB_GetBoot0(hal_flash_t instance)
HAL_FLASH_ITF_OB_GetRDPLevel(hal_flash_t instance)
HAL_FLASH_ITF_IsEnabledLowPWRReadMode(hal_flash_t instance)
HAL_FLASH_ITF_OB_IsEnabledHDPArea(hal_flash_t instance, hal_flash_bank_t bank)
HAL_FLASH_ITF_OB_IsEnabledHDPArea(hal_flash_t instance, hal_flash_bank_t bank)
Note PCROP (readout protection/PCROP enable/disable) is not implemented in the HAL2 |
|
Example usage |
/* HAL1 usage */
FLASH_AdvOBProgramInitTypeDef adv;
HAL_FLASHEx_AdvOBGetConfig(&adv);
|
/* HAL2 usage sequence. this option bytes features are available on some STM32 series ONLY */
hal_flash_itf_ob_boot_state_t boot0 = HAL_FLASH_ITF_OB_GetBoot0(HAL_FLASH);
hal_flash_itf_ob_rdp_level_t rdp = HAL_FLASH_ITF_OB_GetRDPLevel(HAL_FLASH);
hal_flash_itf_low_pwr_read_status_t lpr = HAL_FLASH_ITF_IsEnabledLowPWRReadMode(HAL_FLASH);
hal_flash_itf_ob_hdp_area_status_t hdp_status = HAL_FLASH_ITF_OB_IsEnabledHDPArea(HAL_FLASH, HAL_FLASH_BANK_1);
|
Related concepts: Fully rework HAL Flash driver APIs.
Related use case: User application option-bytes configuration
Programs advanced option bytes. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
|
/* HAL2 (ITF) prototypes - verified */
HAL_FLASH_ITF_OB_SetBoot0(hal_flash_t instance, hal_flash_itf_ob_boot_state_t state);
HAL_FLASH_ITF_OB_SetRDPLevel(hal_flash_t instance, hal_flash_itf_ob_rdp_level_t level);
HAL_FLASH_ITF_OB_SetHDPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t page_nbr);
HAL_FLASH_ITF_EnableLowPWRReadMode(hal_flash_t instance);
HAL_FLASH_ITF_DisableLowPWRReadMode(hal_flash_t instance);
|
|
Example usage |
/* HAL1 usage */
FLASH_AdvOBProgramInitTypeDef adv;
adv.OptionType = OPTIONBYTE_WRP; /* group to configure */
adv.Banks = FLASH_BANK_1; /* target bank(s) for HDP/other area settings */
adv.BootConfig = <BOOT_VALUE>;
HAL_FLASHEx_AdvOBProgram(&adv);
|
/* HAL2 usage */
HAL_FLASH_ITF_OB_SetBoot0(HAL_FLASH, HAL_FLASH_ITF_OB_BOOT_HIGH);
HAL_FLASH_ITF_OB_SetRDPLevel(HAL_FLASH, HAL_FLASH_ITF_OB_RDP_LEVEL_0);
/* HDP area (choose the variant matching the series): */
HAL_FLASH_ITF_OB_SetHDPArea(HAL_FLASH, HAL_FLASH_BANK_1, 4);
HAL_FLASH_ITF_EnableLowPWRReadMode(HAL_FLASH);
|
Related concepts: Fully rework HAL Flash driver APIs.
Computes the CRC of a FLASH memory area. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
/* HAL1 */
HAL_StatusTypeDef HAL_FLASHEx_ComputeCRC(FLASH_CRCInitTypeDef *pCRCInit, uint32_t *CRC_Result);
|
/* HAL2 prototypes */
HAL_FLASH_ComputeCRCByBank(hal_flash_handle_t *hflash,
hal_flash_bank_t bank,
hal_flash_crc_burst_size_t burst_size,
uint32_t timeout_msec);
HAL_FLASH_ComputeCRCByBank_IT(hal_flash_handle_t *hflash,
hal_flash_bank_t bank,
hal_flash_crc_burst_size_t burst_size);
HAL_FLASH_ComputeCRCByAddr(hal_flash_handle_t *hflash,
hal_flash_bank_t bank,
hal_flash_crc_burst_size_t burst_size,
uint32_t start_addr,
uint32_t end_addr,
uint32_t timeout_msec);
HAL_FLASH_ComputeCRCByAddr_IT(hal_flash_handle_t *hflash,
hal_flash_bank_t bank,
hal_flash_crc_burst_size_t burst_size,
uint32_t start_addr,
uint32_t end_addr);
HAL_FLASH_ComputeCRCByPage(hal_flash_handle_t *hflash,
hal_flash_bank_t bank,
hal_flash_crc_burst_size_t burst_size,
uint32_t start_page,
uint32_t nb_pages,
uint32_t timeout_msec);
HAL_FLASH_ComputeCRCByPage_IT(hal_flash_handle_t *hflash,
hal_flash_bank_t bank,
hal_flash_crc_burst_size_t burst_size,
uint32_t start_page,
uint32_t nb_pages);
|
|
Example usage |
/* HAL1 usage */
FLASH_CRCInitTypeDef crc;
uint32_t crc_result;
/* Example: compute CRC over 2 sectors starting at sector 4 of BANK 1 */
crc.TypeCRC = FLASH_CRC_SECTORS; /* or FLASH_CRC_BANK, FLASH_CRC_ADDRESS */
crc.BurstSize = FLASH_CRC_BURST_SIZE_16;/* enum value from @ref FLASHEx_CRC_Burst_Size */
crc.Bank = FLASH_BANK_1; /* FLASH_BANK_1 or FLASH_BANK_2 */
crc.Sector = FLASH_SECTOR_4; /* starting sector */
crc.NbSectors = 2; /* number of sectors */
crc.CRCStartAddr= 0x08020000U; /* used when TypeCRC == FLASH_CRC_ADDRESS */
crc.CRCEndAddr = 0x080207FFU; /* end address */
HAL_FLASHEx_ComputeCRC(&crc, &crc_result);
|
/* HAL2 usage example (bank, polling) */
hal_flash_handle_t hflash;
uint32_t start_addr = 0x08020000U; /* start address */
uint32_t end_addr = 0x080207FFU; /* end address */
HAL_FLASH_ComputeCRCByAddr(&hflash, HAL_FLASH_BANK_1, HAL_FLASH_CRC_BURST_SIZE_16, start_addr, end_addr, 100);
HAL_FLASH_ComputeCRCByBank(&hflash, HAL_FLASH_BANK_1, HAL_FLASH_CRC_BURST_SIZE_16, 100 /* ms timeout */);
|
Related concepts: Fully rework HAL Flash driver APIs.
Configures the base address block attributes. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_StatusTypeDef HAL_FLASHEx_ConfigBBAttributes(FLASH_BBAttributesTypeDef *pBBAttributes)
|
- HAL_FLASH_ITF_SetSecAttr(hal_flash_t instance, uint32_t item, hal_flash_itf_sec_attr_t sec_attr);
- HAL_FLASH_ITF_SetPrivAttr(hal_flash_t instance, uint32_t item, hal_flash_itf_priv_attr_t priv_attr);
|
Related concepts: Fully rework HAL Flash driver APIs.
Configures high-density protection extension. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_StatusTypeDef HAL_FLASHEx_ConfigHDPExtension(const FLASH_HDPExtensionTypeDef *pHDPExtension);
|
/* In case of HDP area OB */
HAL_FLASH_ITF_OB_SetHDPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t page_nbr);
/* In case of HDP area extended is not an OB */
HAL_FLASH_ITF_SetHDPExtArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t page_nbr);
|
|
Example usage |
FLASH_HDPExtensionTypeDef hdpExtension;
hdpExtension.Banks = /* target bank(s), e.g. FLASH_BANK_1 */;
hdpExtension.NbSectors = /* number of sectors to extend, e.g. 4 */;
HAL_FLASHEx_ConfigHDPExtension(&hdpExtension);
|
/* HAL2 usage (parameter-only) */
hal_flash_bank_t bank; /* target bank */
uint32_t page_nbr; /* number of pages */
HAL_FLASH_ITF_OB_SetHDPArea(HAL_FLASH, bank, page_nbr);
/* or extended variant */
HAL_FLASH_ITF_SetHDPExtArea(HAL_FLASH, bank, page_nbr);
|
Related concepts: Fully rework HAL Flash driver APIs.
Configures low power read mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_StatusTypeDef HAL_FLASHEx_ConfigLowPowerRead(uint32_t ConfigLPM)
|
HAL_FLASH_ITF_EnableLowPWRReadMode(hal_flash_t instance);
HAL_FLASH_ITF_DisableLowPWRReadMode(hal_flash_t instance);
|
Related concepts: Fully rework HAL Flash driver APIs.
Configures privilege mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
void HAL_FLASHEx_ConfigPrivMode(uint32_t PrivMode);
|
HAL_FLASH_ITF_SetPrivAttr(hal_flash_t instance, uint32_t item, hal_flash_itf_priv_attr_t priv_attr);
|
|
Example usage |
uint32_t priv_mode = FLASH_SPRIV_GRANTED; /* or FLASH_SPRIV_DENIED, FLASH_NSPRIV_GRANTED, FLASH_NSPRIV_DENIED */
HAL_FLASHEx_ConfigPrivMode(priv_mode);
|
uint32_t item = /* privilege attribute item */;
hal_flash_itf_priv_attr_t priv_attr = /* privilege attribute value */;
HAL_FLASH_ITF_SetPrivAttr(HAL_FLASH, item, priv_attr);
|
Note
HAL1 configures a global privilege mode with a single mask value.
HAL2 uses item-scoped privilege attributes via
HAL_FLASH_ITF_SetPrivAttr
for finer granularity.
A direct one-shot global setter is not exposed.
Configures security inversion. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_ConfigSecInversion(uint32_t SecInvState)
|
HAL_FLASH_ITF_SetClkSecStateInversion(hal_flash_t instance, hal_flash_clk_sec_invert_state_t clk_sec_invert_state);
|
Disables the debugger. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
void HAL_FLASHEx_EnableDebugger(void)
void HAL_FLASHEx_DisableDebugger(void)
|
HAL_FLASH_ITF_EnableDebugAccess(hal_flash_t instance);
HAL_FLASH_ITF_DisableDebugAccess(hal_flash_t instance);
|
Disables ECC correction interrupt for all FLASH banks. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_DisableEccCorrectionInterrupt();
HAL_FLASHEx_DisableEccCorrectionInterrupt_Bank1();
HAL_FLASHEx_DisableEccCorrectionInterrupt_Bank2();
|
/* Generic (single context) variant */
HAL_FLASH_ITF_ECC_DisableIT(hal_flash_t instance);
/* Bank-scoped single-error (correction) interrupt variant */
HAL_FLASH_ITF_ECC_DisableSingleErrorIT(hal_flash_t instance, hal_flash_bank_t bank);
Note HAL1 provides a single global disable call. HAL2 exposes granular variants: generic (all), or per-bank single-error (correction) interrupt. Use only the form available for the target series (feature-gated by USE_HAL_FLASH_ECC). |
|
Example usage |
/* HAL1 usage */
HAL_FLASHEx_DisableEccCorrectionInterrupt();
HAL_FLASHEx_DisableEccCorrectionInterrupt_Bank1();
HAL_FLASHEx_DisableEccCorrectionInterrupt_Bank2();
|
/* HAL2 parameter-only usage examples */
hal_flash_t instance; /* FLASH instance */
hal_flash_bank_t bank; /* bank for single-error IT variant */
/* Generic single-context series */
HAL_FLASH_ITF_ECC_DisableIT(instance);
/* Bank-scoped single-error (correction) interrupt variant */
HAL_FLASH_ITF_ECC_DisableSingleErrorIT(instance, bank);
|
Disables ECC detection interrupt for all FLASH banks. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_DisableEccDetectionInterrupt();
HAL_FLASHEx_DisableEccDetectionInterrupt_Bank1();
HAL_FLASHEx_DisableEccDetectionInterrupt_Bank2();
|
/* HAL2 (ITF) prototypes observed across series */
HAL_FLASH_ITF_ECC_DisableIT(hal_flash_t instance); /* generic ECC interrupt (single+double) disable */
HAL_FLASH_ITF_ECC_DisableDoubleErrorIT(hal_flash_t instance, /* OR double-error (detection) interrupt disable */
hal_flash_bank_t bank);
|
|
Example usage |
/* HAL1 usage */
HAL_FLASHEx_DisableEccDetectionInterrupt();
HAL_FLASHEx_DisableEccDetectionInterrupt_Bank1();
HAL_FLASHEx_DisableEccDetectionInterrupt_Bank2();
|
/* HAL2 usage (parameter-only) */
hal_flash_t instance; /* FLASH instance */
hal_flash_bank_t bank; /* target bank for double-error IT variant */
/* Disable all ECC (single+double) interrupts (generic series) */
HAL_FLASH_ITF_ECC_DisableIT(instance);
/* OR Disable only double-error (detection) interrupt for a specific bank */
HAL_FLASH_ITF_ECC_DisableDoubleErrorIT(instance, bank);
Note
HAL1 “Detection” interrupt corresponds to the double-error (uncorrectable) ECC event.
HAL2 splits ECC handling into:
- Generic disable (all ECC error interrupts) via
Use only the prototypes available for the target series (feature-gated by USE_HAL_FLASH_ECC). No one-shot named “Detection” function exists in HAL2. |
Related concepts: Fully rework HAL Flash driver APIs.
Disables FLASH sleep mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_DisableFlashSleepMode()
|
HAL_FLASH_ITF_DisablePWRDownSleepMode(hal_flash_t instance)
|
Disables run power-down mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_DisableRunPowerDown()
|
/* HAL2 prototypes (run power-down) */
HAL_FLASH_ITF_EnablePWRDownRunMode(hal_flash_t instance, hal_flash_bank_t bank);
|
Handles FLASH ECC double error (ECCD) interrupts. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_ECCD_IRQHandler()
|
/* HAL2 prototypes (ECC interrupt handling) */
void HAL_FLASH_ECC_IRQHandler(hal_flash_handle_t *hflash); /* handles enabled FLASH ECC error interrupts */
Note
HAL1 provides a dedicated double-error (ECCD) IRQ handler.
HAL2 consolidates ECC interrupt servicing into
|
|
Example usage |
/* HAL1 usage */
HAL_FLASHEx_ECCD_IRQHandler();
|
/* HAL2 usage (parameter-only) */
hal_flash_handle_t hflash; /* FLASH handle populated elsewhere */
HAL_FLASH_ECC_IRQHandler(&hflash); /* services single and double ECC error sources */
|
Related concepts: Introduce specialized IRQ handlers
User callback function called on FLASH ECC correction event. ¶
|
HAL1 |
HAL2 |
|---|---|
HAL_FLASHEx_EccCorrectionCallback();
HAL_FLASHEx_EccDetectionCallback();
|
/* HAL2 prototypes (ECC error callback) */
HAL_FLASH_ECC_ErrorCallback(hal_flash_handle_t *hflash, hal_flash_bank_t bank);
|
Related concepts: Introduce specialized IRQ handlers
Enables ECC correction interrupt for all FLASH banks. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_EnableEccCorrectionInterrupt();
HAL_FLASHEx_EnableEccCorrectionInterrupt_Bank1();
HAL_FLASHEx_EnableEccCorrectionInterrupt_Bank2();
|
/* HAL2 (ITF) */
HAL_FLASH_ITF_ECC_EnableIT(hal_flash_t instance); /* generic enable (single + double error sources) */
HAL_FLASH_ITF_ECC_EnableSingleErrorIT(hal_flash_t instance, /* OR per-bank single-error (correction) enable */
hal_flash_bank_t bank); /* present only on series supporting bank granularity */
Note HAL1 exposes a single global correction enable . HAL2 provides either:
Use only the prototype(s) available for the target series (feature gated by
|
|
Example usage |
/* HAL1 usage */
HAL_FLASHEx_EnableEccCorrectionInterrupt();
HAL_FLASHEx_EnableEccCorrectionInterrupt_Bank1();
HAL_FLASHEx_EnableEccCorrectionInterrupt_Bank2();
|
/* Generic single-context or all-banks enable */
HAL_FLASH_ITF_ECC_EnableIT(HAL_FLASH);
/* OR Bank-scoped single-error (correction) enable (if available) */
HAL_FLASH_ITF_ECC_EnableSingleErrorIT(HAL_FLASH, HAL_FLASH_BANK_1);
HAL_FLASH_ITF_ECC_EnableSingleErrorIT(HAL_FLASH, HAL_FLASH_BANK_2);
|
Enables ECC detection interrupt for all FLASH banks. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_EnableEccDetectionInterrupt();
HAL_FLASHEx_EnableEccDetectionInterrupt_Bank1();
HAL_FLASHEx_EnableEccDetectionInterrupt_Bank2();
|
/* HAL2 (ITF) double-error (detection) interrupt enable prototypes */
HAL_FLASH_ITF_ECC_EnableIT(hal_flash_t instance); /* generic enable (single + double error sources) */
HAL_FLASH_ITF_ECC_EnableDoubleErrorIT(hal_flash_t instance, /* OR per-bank double-error (uncorrectable) enable */
hal_flash_bank_t bank); /* only on bank-granular series */
Note HAL1 separates correction (single ECC error) and detection (double ECC error) enables. HAL2 consolidates enabling paths:
These services can be enabled and disabled by configuring the define
|
|
Example usage |
/* HAL1 usage */
HAL_FLASHEx_EnableEccDetectionInterrupt();
HAL_FLASHEx_EnableEccDetectionInterrupt_Bank1();
HAL_FLASHEx_EnableEccDetectionInterrupt_Bank2();
|
/* Generic single-context or all-banks enable (also covers detection) */
HAL_FLASH_ITF_ECC_EnableIT(instance);
/* OR Per-bank double-error (detection) enable (if available) */
HAL_FLASH_ITF_ECC_EnableDoubleErrorIT(HAL_FLASH, HAL_FLASH_BANK_1);
HAL_FLASH_ITF_ECC_EnableDoubleErrorIT(HAL_FLASH, HAL_FLASH_BANK_2);
|
Enables FLASH sleep mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_EnableFlashSleepMode();
|
/* HAL2 prototypes (sleep power-down enable) */
HAL_FLASH_ITF_EnablePWRDownSleepMode(hal_flash_t instance);
|
Enables power-down mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_EnablePowerDown();
|
/* HAL2 (ITF) prototypes - sleep power-down mapping */
HAL_FLASH_ITF_EnablePWRDownSleepMode(hal_flash_t instance);
|
Enables run power-down mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_EnableRunPowerDown();
|
/* HAL2 (ITF) prototypes - run power-down mapping */
HAL_FLASH_ITF_EnablePWRDownRunMode(hal_flash_t instance, hal_flash_bank_t bank);
|
Enables security hide protection. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_EnableSecHideProtection(uint32_t Banks);
|
HAL_FLASH_ITF_OB_SetHDPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t page_nbr);
|
|
Example usage |
/* HAL1 usage */
HAL_FLASHEx_EnableSecHideProtection(FLASH_BANK_1);
|
/* HAL2 usage */
hal_flash_bank_t bank = HAL_FLASH_BANK1; /* target bank for hide area */
uint32_t page_nbr; /* number of pages to include in hide area */
HAL_FLASH_ITF_OB_SetHDPArea(HAL_FLASH, bank, page_nbr);
|
Enables security memory protection. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_EnableSecMemProtection(uint32_t Bank);
|
/* HAL2 prototypes (page security protection) */
HAL_FLASH_ITF_EnablePageSecProtection(hal_flash_t instance);
|
Checks if FLASH memory is empty. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_FlashEmptyCheck(void);
|
/* HAL2 prototype (boot location emptiness query) */
hal_flash_itf_empty_boot_location_t HAL_FLASH_ITF_GetEmptyBootLocation(hal_flash_t instance);
|
Related concepts: Fully rework HAL Flash driver APIs.
Forces FLASH memory to be empty. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_ForceFlashEmpty(uint32_t FlashEmpty);
|
/* HAL2 prototype (force boot location emptiness state) */
HAL_FLASH_ITF_SetEmptyBootLocation(hal_flash_t instance, hal_flash_itf_empty_boot_location_t empty_boot);
|
|
Example usage |
/* HAL1 usage */
/* Force FLASH empty flag so subsequent resets (without option byte loader) see empty */
HAL_FLASHEx_ForceFlashEmpty(FLASH_PROG_EMPTY);
|
/* HAL2 usage */
HAL_FLASH_ITF_SetEmptyBootLocation(HAL_FLASH, HAL_FLASH_ITF_BOOT_LOCATION_EMPTY);
|
Gets low power read configuration. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
uint32_t HAL_FLASHEx_GetLowPowerRead(void);
|
hal_flash_itf_low_pwr_read_status_t HAL_FLASH_ITF_IsEnabledLowPWRReadMode(hal_flash_t instance);
|
Gets privilege mode configuration. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
uint32_t HAL_FLASHEx_GetPrivMode(void);
|
hal_flash_itf_priv_attr_t HAL_FLASH_ITF_GetPrivAttr(hal_flash_t instance, uint32_t item);
|
|
Example usage |
/* HAL1 usage */
uint32_t priv = HAL_FLASHEx_GetPrivMode();
|
/* HAL2 usage */
uint32_t item; /* privilege-scoped item (enum/mask defined per series) */
hal_flash_itf_priv_attr_t priv_attr = HAL_FLASH_ITF_GetPrivAttr(HAL_FLASH, item);
|
Note
HAL1 exposes a single global privilege configuration via a combined mask. reading returns aggregated bits.
HAL2 replaces this with item-scoped privilege attributes retrievable per
item
using
HAL_FLASH_ITF_GetPrivAttr.
Gets security inversion configuration. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_GetSecInversion(void);
|
HAL_FLASH_ITF_GetClkSecStateInversion(hal_flash_t instance)
|
Unlock/Locks FLASH Bank 1 to prevent write/erase operations. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
/*unlock*/
HAL_FLASH_Unlock();
HAL_FLASHEx_Unlock_Bank1();
HAL_FLASHEx_Lock_Bank2();
/*lock*/
HAL_FLASH_Lock();
HAL_FLASHEx_Lock_Bank1();
HAL_FLASHEx_Lock_Bank2();
|
/*unlock */
HAL_FLASH_ITF_Unlock(hal_flash_t instance);
HAL_FLASH_ITF_UnlockBank(hal_flash_t instance, hal_flash_bank_t bank);
/*lock*/
HAL_FLASH_ITF_Lock(hal_flash_t instance);
HAL_FLASH_ITF_LockBank(hal_flash_t instance, hal_flash_bank_t bank);
|
|
Example usage |
/* HAL1 usage */
/*unlock*/
HAL_FLASH_Unlock();
HAL_FLASHEx_Unlock_Bank1();
HAL_FLASHEx_Lock_Bank2();
/*lock*/
HAL_FLASH_Lock();
HAL_FLASHEx_Lock_Bank1();
HAL_FLASHEx_Lock_Bank2();
|
/* HAL2 usage*/
/*unlock*/
HAL_FLASH_ITF_Unlock(HAL_FLASH);
HAL_FLASH_ITF_UnlockBank(HAL_FLASH, HAL_FLASH_BANK_1 );
HAL_FLASH_ITF_UnlockBank(HAL_FLASH, HAL_FLASH_BANK_2 );
/*lock*/
HAL_FLASH_ITF_Lock(HAL_FLASH);
HAL_FLASH_ITF_LockBank(HAL_FLASH, HAL_FLASH_BANK_1);
HAL_FLASH_ITF_LockBank(HAL_FLASH, HAL_FLASH_BANK_2);
|
Locks the option bytes. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASH_OB_Lock()
HAL_FLASH_OB_Unlock()
|
HAL_FLASH_ITF_OB_Lock(hal_flash_t instance);
HAL_FLASH_ITF_OB_Unlock(hal_flash_t instance);
|
Gets option byte configuration ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_OBGetConfig();
|
/* HAL2 (ITF) granular OB getters (representative subset; series-dependent) */
hal_flash_itf_ob_boot_state_t HAL_FLASH_ITF_OB_GetBoot0(hal_flash_t instance);
hal_flash_itf_ob_rdp_level_t HAL_FLASH_ITF_OB_GetRDPLevel(hal_flash_t instance);
hal_flash_itf_low_pwr_read_status_t HAL_FLASH_ITF_IsEnabledLowPWRReadMode(hal_flash_t instance);
hal_flash_itf_ob_hdp_area_status_t HAL_FLASH_ITF_OB_IsEnabledHDPArea(hal_flash_t instance, hal_flash_bank_t bank);
void HAL_FLASH_ITF_OB_GetWRPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t *first_page, uint32_t *last_page);
hal_flash_itf_ob_bor_level_t HAL_FLASH_ITF_OB_GetBORLevel(hal_flash_t instance);
hal_flash_itf_ob_wdg_mode_t HAL_FLASH_ITF_OB_GetIWDGMode(hal_flash_t instance);
hal_flash_itf_ob_wdg_mode_t HAL_FLASH_ITF_OB_GetWWDGMode(hal_flash_t instance);
hal_flash_itf_ob_boot_selection_t HAL_FLASH_ITF_OB_GetBootSelection(hal_flash_t instance);
Note
HAL1 aggregates multiple option byte fields into a single structure returned by
|
|
Example usage |
/* HAL1 usage */
FLASH_OBProgramInitTypeDef ob;
HAL_FLASHEx_OBGetConfig(&ob);
/* ob.RDPLevel, ob.BORLevel, ob.WRPArea, ob.OptionType etc. populated */
|
/* HAL2 usage (granular assembly) */
hal_flash_bank_t bank = HAL_FLASH_BANK_1; /* target bank for area-based queries */
hal_flash_itf_ob_boot_state_t boot0 = HAL_FLASH_ITF_OB_GetBoot0(HAL_FLASH);
hal_flash_itf_ob_rdp_level_t rdp = HAL_FLASH_ITF_OB_GetRDPLevel(HAL_FLASH);
hal_flash_itf_low_pwr_read_status_t lpr = HAL_FLASH_ITF_IsEnabledLowPWRReadMode(HAL_FLASH);
hal_flash_itf_ob_bor_level_t bor = HAL_FLASH_ITF_OB_GetBORLevel(HAL_FLASH);
hal_flash_itf_ob_wdg_mode_t iwdg_mode = HAL_FLASH_ITF_OB_GetIWDGMode(HAL_FLASH);
hal_flash_itf_ob_wdg_mode_t wwdg_mode = HAL_FLASH_ITF_OB_GetWWDGMode(HAL_FLASH);
hal_flash_itf_ob_boot_selection_t boot_sel = HAL_FLASH_ITF_OB_GetBootSelection(HAL_FLASH);
uint32_t wrp_first = 0, wrp_last = 0;
HAL_FLASH_ITF_OB_GetWRPArea(HAL_FLASH, bank, &wrp_first, &wrp_last);
/* Optional HDP status (series-dependent) */
hal_flash_itf_ob_hdp_area_status_t hdp_status = HAL_FLASH_ITF_OB_IsEnabledHDPArea(HAL_FLASH, bank);
|
Locks option byte key. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_OBK_Lock();
|
HAL_FLASH_ITF_OBK_Lock(HAL_FLASH);
|
Swaps option byte key. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_OBK_Swap(uint32_t SwapOffset);
|
HAL_FLASH_ITF_OBK_SwapPage(hal_flash_t instance, hal_flash_itf_obk_area_t area, uint32_t obk_offset);
|
|
Example usage |
/* HAL1 usage */
uint32_t SwapOffset;
HAL_FLASHEx_OBK_Swap(SwapOffset);
|
/* HAL2 usage */
hal_flash_itf_obk_area_t area; /* target OBK area (e.g. HAL_FLASH_ITF_OBK_AREA_1) */
uint32_t obk_offset; /* offset within area defining swap start page */
HAL_FLASH_ITF_OBK_SwapPage(HAL_FLASH, area, obk_offset);
|
Swaps option byte key using interrupt mode. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_OBK_Swap_IT(uint32_t SwapOffset);
|
/* HAL2 (ITF) interrupt variant prototype */
HAL_FLASH_ITF_OBK_SwapPage_IT(hal_flash_t instance, hal_flash_itf_obk_area_t area, uint32_t obk_offset);
|
|
Example usage |
/* HAL1 usage */
uint32_t SwapOffset; /* swap start offset (page-aligned as per series requirements) */
HAL_FLASHEx_OBK_Swap_IT(SwapOffset);
|
/* HAL2 usage */
hal_flash_itf_obk_area_t area; /* OBK area (e.g. HAL_FLASH_ITF_OBK_AREA_1) */
uint32_t obk_offset; /* swap start offset within the area */
HAL_FLASH_ITF_OBK_SwapPage_IT(HAL_FLASH, area, obk_offset);
|
Unlocks option byte key. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_OBK_Unlock();
|
/* HAL2 (ITF) prototype */
HAL_FLASH_ITF_OBK_Unlock(hal_flash_t instance);
|
Programs option bytes ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit);
|
Note
/* HAL2 granular (ITF) option byte setters (representative subset; series-dependent) */
HAL_FLASH_ITF_OB_SetBoot0(hal_flash_t instance, hal_flash_itf_ob_boot_state_t state);
HAL_FLASH_ITF_OB_SetBootSelection(hal_flash_t instance, hal_flash_itf_ob_boot_selection_t boot_select);
HAL_FLASH_ITF_OB_SetRDPLevel(hal_flash_t instance, hal_flash_itf_ob_rdp_level_t level);
HAL_FLASH_ITF_OB_SetBORLevel(hal_flash_t instance, hal_flash_itf_ob_bor_level_t bor_level);
HAL_FLASH_ITF_OB_SetIWDGMode(hal_flash_t instance, hal_flash_itf_ob_wdg_mode_t mode);
HAL_FLASH_ITF_OB_SetWWDGMode(hal_flash_t instance, hal_flash_itf_ob_wdg_mode_t mode);
HAL_FLASH_ITF_OB_SetWRPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t first_page, uint32_t last_page);
void HAL_FLASH_ITF_OB_GetWRPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t *first_page, uint32_t *last_page);
HAL_FLASH_ITF_OB_SetPCROPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t start_addr, uint32_t end_addr); /* if PCROP supported */
HAL_FLASH_ITF_OB_SetHDPArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t page_nbr);
HAL_FLASH_ITF_SetHDPExtArea(hal_flash_t instance, hal_flash_bank_t bank, uint32_t page_nbr); /* HDP extension (series-dependent) */
HAL_FLASH_ITF_OB_SetBoot1(hal_flash_t instance, hal_flash_itf_ob_boot_state_t state); /* when exposed */
HAL_FLASH_ITF_OB_EnablePCROPEraseRDPRegression(hal_flash_t instance, hal_flash_bank_t bank); /* feature gated */
|
|
Example usage |
/* HAL1 usage */
FLASH_OBProgramInitTypeDef ob;
ob.OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_BOOTCONFIG; /* OR-combined selection */
ob.RDPLevel = OB_RDP_LEVEL_0;
ob.BORLevel = OB_BOR_LEVEL_LOW;
ob.WRPArea = <WRP_AREA_VALUE>; /* sector/page range encoded */
ob.USERConfig = (OB_IWDG_SW | OB_WWDG_SW); /* user config bitfield */
ob.BootConfig = <BOOT_SELECTION>; /* boot selection encoded */
HAL_FLASHEx_OBProgram(&ob);
|
/* HAL2 usage (granular multi-call sequence). Each logical option programmed via its dedicated setter. */
hal_flash_bank_t bank; /* target bank for area-scoped options */
uint32_t wrp_first_page, wrp_last_page; /* write protection page window */
uint32_t pcrop_start_addr, pcrop_end_addr;/* PCROP address boundaries (aligned) */
uint32_t hdp_page_nbr; /* HDP base pages */
uint32_t hdp_ext_page_nbr; /* HDP extension pages */
HAL_FLASH_ITF_OB_SetRDPLevel(HAL_FLASH, HAL_FLASH_ITF_OB_RDP_LEVEL_0);
HAL_FLASH_ITF_OB_SetBORLevel(HAL_FLASH, HAL_FLASH_ITF_OB_BOR_LEVEL_LOW);
HAL_FLASH_ITF_OB_SetBootSelection(HAL_FLASH, HAL_FLASH_ITF_OB_BOOT_SEL_FLASH);
HAL_FLASH_ITF_OB_SetBoot0(HAL_FLASH, HAL_FLASH_ITF_OB_BOOT_HIGH);
HAL_FLASH_ITF_OB_SetIWDGMode(HAL_FLASH, HAL_FLASH_ITF_OB_WDG_MODE_SW);
HAL_FLASH_ITF_OB_SetWWDGMode(HAL_FLASH, HAL_FLASH_ITF_OB_WDG_MODE_SW);
HAL_FLASH_ITF_OB_SetWRPArea(HAL_FLASH, bank, wrp_first_page, wrp_last_page);
HAL_FLASH_ITF_OB_SetPCROPArea(HAL_FLASH, bank, pcrop_start_addr, pcrop_end_addr);
HAL_FLASH_ITF_OB_SetHDPArea(HAL_FLASH, bank, hdp_page_nbr);
HAL_FLASH_ITF_SetHDPExtArea(HAL_FLASH, bank, hdp_ext_page_nbr);
HAL_FLASH_ITF_OB_EnablePCROPEraseRDPRegression(HAL_FLASH, bank);
|
Gets write protection for bank 2. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_OB_GetBank2WRP();
|
/* HAL2 generic WRP area getter (Bank1 / Bank2) */
void HAL_FLASH_ITF_OB_GetWRPArea(hal_flash_t instance,
hal_flash_bank_t bank,
uint32_t *first_page,
uint32_t *last_page);
|
|
Example usage |
/* HAL1 usage */
/* Retrieve Bank2 write protection window (returns encoded range in HAL1-specific struct or registers) */
HAL_FLASHEx_OB_GetBank2WRP();
|
/* HAL2 usage */
uint32_t first_page = 0, last_page = 0;/* outputs for WRP window */
/* Query Bank2 write protection window */
HAL_FLASH_ITF_OB_GetWRPArea(HAL_FLASH, HAL_FLASH_BANK_2, &first_page, &last_page);
|
Note
HAL1 provides a dedicated Bank2-specific getter
HAL_FLASHEx_OB_GetBank2WRP.
HAL2 unifies write protection querying via
HAL_FLASH_ITF_OB_GetWRPArea
which accepts a bank parameter (Bank1 or Bank2) and returns the window through output pointers.
Starts the FLASH interface clock. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASHEx_StartFlashInterfaceClk();
|
|
Launches the option byte programming. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASH_OB_Launch();
|
HAL_FLASH_ITF_OB_Launch(hal_flash_t instance);
|
Callback called on FLASH operation error. ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Function prototype |
HAL_FLASH_OperationErrorCallback()
|
/* HAL2 callback (FLASH ITF option bytes / operation error) */
void HAL_FLASH_ITF_OB_ErrorCallback(hal_flash_t instance);
|
Note
HAL1 exposes
HAL_FLASH_OperationErrorCallback
as callback function invoked on generic FLASH operation errors (erase/program/OB sequence) inside its IRQ handler.
HAL2 splits interrupt servicing paths between IO layer and FLASH ITF (option bytes / configuration domain).
The operation error callback for the FLASH ITF path is
HAL_FLASH_ITF_OB_ErrorCallback.
operations (program/erase/..) error callbacks are as described in :ref:` here <hal_flash_exported_function_hal_flash_endofoperationcallback>`.
the HAL_FLASH_ITF_OB_ErrorCallback is called by
HAL_FLASH_ITF_IRQHandler(), and the operation error callbacks are called by
HAL_FLASH_IRQHandler().